package object.connector;
import object.mass.Mass;
import sim.Simulation;

/**
 * A spring with a rest length that changes over time based
 * on a sinusoidal wave.
 * @author Niel Lebeck and Wynne Lok
 *
 */
public class Muscle extends Spring {
    private static final double DEGREE_INCREMENT = 8;

    private double myAmplitude;
    private double myDegree;
    private double myBaseLength;

    /**
     * @param start starting Mass
     * @param end ending Mass
     * @param length base rest length
     * @param kVal spring constant
     * @param amp amplitude of sine wave
     */
    public Muscle (Mass start, Mass end, double length, double kVal,
            double amp) {
        super(start, end, length, kVal);
        myBaseLength = length;
        myAmplitude = amp;
        myDegree = 0.0;
    }

    /**
     * A muscle applies forces like a spring, but updates its rest length
     * according to a sinusoidal function first.
     * @param canvas the current Simulation containing this Muscle
     * @param dt the interval of time that has passed
     */
    @Override
    public void update (Simulation canvas, double dt) {
        System.out.println(dt);
        myDegree += DEGREE_INCREMENT * dt;
        if (myDegree > Math.PI * 2) {
            myDegree = 0.0;
        }
        this.setLength(this.myBaseLength + myAmplitude * Math.sin(myDegree));
        super.update(canvas, dt);
    }

}
